package com.ymatou.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.RepairLiveRoomStatusBean;
import com.ymatou.iapi.livebuyer.service.RepairLiveRoomStatusCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*修复直播间状态
*FreeMaker Template自动生成代码
*@2018/09/07
*具体逻辑：status 2->3
*/
@TestSuite
public class Ts_RepairLiveRoomStatus{
	private static RepairLiveRoomStatusBean repairliveroomstatusBean;
	private static RepairLiveRoomStatusCall repairliveroomstatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修复直播间状态");
	}

	@Before
	public void caseUp() {
		repairliveroomstatusBean=new RepairLiveRoomStatusBean();
		repairliveroomstatusCall=new RepairLiveRoomStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(repairliveroomstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RepairLiveRoomStatus_001() {
		Logger.start(true,"修复直播间状态，无liveid");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			new LiveRoomWapper().updateLiveRoomPushStatus(createlive.getId(),2);
			new LiveRoomWapper().updateLiveRoomTime(YMTDateUtil.getBeforeOrNextHour(-1), YMTDateUtil.getBeforeOrNextHour(1),YMTDateUtil.getBeforeOrNextHour(1), createlive.getId());
			repairliveroomstatusCall.setData(repairliveroomstatusBean);
			repairliveroomstatusCall.callService();		
			LiveRoom liveRoom = new LiveRoomWapper().selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(3, liveRoom.getLiveStatus(), "验证直播间的状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RepairLiveRoomStatus_002() {
		Logger.start(true,"修复直播间状态,有liveid,status=2");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			new LiveRoomWapper().updateLiveRoomPushStatus(createlive.getId(),2);
			new LiveRoomWapper().updateLiveRoomTime(YMTDateUtil.getBeforeOrNextHour(-1), YMTDateUtil.getBeforeOrNextHour(1),YMTDateUtil.getBeforeOrNextHour(1), createlive.getId());
			repairliveroomstatusBean.setLiveId(createlive.getId());
			repairliveroomstatusCall.setData(repairliveroomstatusBean);
			repairliveroomstatusCall.callService();	
			LiveRoom liveRoom = new LiveRoomWapper().selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(3, liveRoom.getLiveStatus(), "验证直播间的状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RepairLiveRoomStatus_003() {
		Logger.start(true,"修复直播间状态,有liveid,status=3");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			new LiveRoomWapper().updateLiveRoomPushStatus(createlive.getId(),3);
			new LiveRoomWapper().updateLiveRoomTime(YMTDateUtil.getBeforeOrNextHour(-1), YMTDateUtil.getBeforeOrNextHour(1),YMTDateUtil.getBeforeOrNextHour(1), createlive.getId());
			repairliveroomstatusBean.setLiveId(createlive.getId());
			repairliveroomstatusCall.setData(repairliveroomstatusBean);
			repairliveroomstatusCall.callService();	
			LiveRoom liveRoom = new LiveRoomWapper().selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(3, liveRoom.getLiveStatus(), "验证直播间的状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RepairLiveRoomStatus_004() {
		Logger.start(true,"修复直播间状态,有liveid,status不为2和3");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			new LiveRoomWapper().updateLiveRoomPushStatus(createlive.getId(),4);
			new LiveRoomWapper().updateLiveRoomTime(YMTDateUtil.getBeforeOrNextHour(-1), YMTDateUtil.getBeforeOrNextHour(1), YMTDateUtil.getBeforeOrNextHour(1),createlive.getId());
			repairliveroomstatusBean.setLiveId(createlive.getId());
			repairliveroomstatusCall.setData(repairliveroomstatusBean);
			repairliveroomstatusCall.callService();	
			LiveRoom liveRoom = new LiveRoomWapper().selectLiveRoomById(createlive.getId());
			//状态不变
			Logger.verifyEquals(4, liveRoom.getLiveStatus(), "验证直播间的状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}